//
//  ViewController.m
//  UI25_litanqi
//
//  Created by 殷殷明静 on 16/8/17.
//  Copyright © 2016年 殷明静. All rights reserved.
//

#import "ViewController.h"
#define WIDTH [UIScreen mainScreen].bounds.size.width
#define HEIGHT [UIScreen mainScreen].bounds.size.height
#import "YMJTableViewCell.h"
@interface ViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) UIView *tableViewHeaderView;
@property (nonatomic, strong) UIImageView *tableViewHeaderViewImageView;
@property (nonatomic, strong) UIImageView *imageView_naVigationBar;
@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    [self.navigationController.navigationBar setBackgroundImage:[[UIImage alloc] init] forBarMetrics:0];
    [self.navigationController.navigationBar setShadowImage:[[UIImage alloc] init]];
    self.imageView_naVigationBar = [[UIImageView alloc] initWithFrame:CGRectMake(0, -20, WIDTH, 64)];
    self.imageView_naVigationBar.image = [UIImage imageNamed:@"tts-navbar"];
    [self.navigationController.navigationBar addSubview:_imageView_naVigationBar];
    self.tableView = [[UITableView alloc] initWithFrame:CGRectMake(0, - 64, WIDTH, HEIGHT) style:UITableViewStylePlain];
    [self.view addSubview:_tableView];
    self.tableView.delegate = self;
    self.tableView.dataSource = self;
    [self.tableView registerNib:[UINib nibWithNibName:@"YMJTableViewCell" bundle:[NSBundle mainBundle]] forCellReuseIdentifier:@"1"];
    self.tableViewHeaderView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, WIDTH, 200)];
    self.tableViewHeaderViewImageView = [[UIImageView alloc] initWithFrame:_tableViewHeaderView.bounds];
    _tableViewHeaderViewImageView.image = [UIImage imageNamed:@"1"];
    [_tableViewHeaderView addSubview:_tableViewHeaderViewImageView];
    self.tableView.tableHeaderView = _tableViewHeaderView;
    
}
- (void)scrollViewDidScroll:(UIScrollView *)scrollView {
    CGFloat offSet_y = scrollView.contentOffset.y;
    CGFloat alpha = (offSet_y + 64) / 200.0f;
    self.imageView_naVigationBar.alpha = alpha;
    if (offSet_y < -64) {
        CGFloat add_height = - (offSet_y + 64);
        CGFloat scale = (200 + add_height) / 200.0f;
        self.tableViewHeaderViewImageView.frame = CGRectMake(-(WIDTH *scale - WIDTH)/ 2, -add_height, WIDTH *scale, 200 + add_height);
    }
}
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
    return 10;
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    YMJTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"1"];
    return cell;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}


@end
